(function( $ ) {
    $.fn.getC = function ( type ) {
        // location.search获取get请求的参数   获取到的数据，是以?开头的
        var search = location.search;
        function parse(search){ 
            var str = search.substring(1);
            var result = {};
            var strs = str.split("&");
            strs.forEach( function(v) {  
                var keyvalue = v.split("="); 
                var name = keyvalue[0]; 
                var value = keyvalue[1]; 
                result[name] = value; 
            }) 
            return result; 
        } 
        var r = parse(search);
        var channelId = r.channelId;
        var sign = r.sign;

        // random30()随机字符穿
        function random30(capacity){
            var data=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];		
            var result="";
            for(var i=0;i<capacity;i++){
                var r=Math.floor(Math.random()*62);	
                result+=data[r];	
            }
            return result
        }

        //读取cookies
        function getCookie(name){
            var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); //正则匹配
            if(arr=document.cookie.match(reg)){
            return unescape(arr[2]);
            }
            else{
            return null;
            }
        }

        //cname 名字/cvalue 值/exdays 时间 
        var expires;
        function setCookie(cname, cvalue, exdays) {
            var d = new Date();
            d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
            var ckv = cname + "=" + cvalue + ";expires=" + d.toGMTString();
            document.cookie = ckv;
        }

        // 判断是否有ck,做相关操作
        var ck;
        function getCK() {
            ck = getCookie("ck");
            if( !ck ) {
                var newCk = random30(30);
                setCookie( "ck", newCk, 1 );
                ck = newCk
            }
        }
        getCK()


        // ajax请求
        var pvp = "/hs/api/v1/pvp";
        $.ajax({
            url: pvp,
            type: "post",
            dataType: "json",
            data: {
                ck: type+"|"+ck+"|"+channelId+"|"+sign+"|"+new Date().getTime()
            },
            success: function(a) {
            }
        })
    }
})(jQuery)

